<?php
namespace app\controller;

use app\BaseController;
use app\model\ArticleModel;
use app\model\Classify;
use app\model\Honor;
use app\model\Product;
use app\model\SysUser;
use think\facade\View;

/**
 * 企业列表
 */
class Company extends BaseController
{
    public function index()
    {

        // 获取参数
        $cid = input('cid', 0);
        View::assign('cid', $cid);

        $classify = Classify::where('id', $cid)->where('deleted', 0)->find();
        View::assign('classify', $classify);

        $list = SysUser::where(['classify_id' => $cid, 'deleted' => 0,'status' => 0])
            ->order('create_time desc')->paginate(10);
        // 把分页数据赋值给模板变量list
        View::assign('list', $list);

        // 获取分页显示
        $page = $list->render();
        // 分页数据
        View::assign('page', $page);

        // 如果是手机访问
        if ($this->isMobile())
        {
            return View::fetch('wap_index');
        } else {
            return View::fetch();
        }
    }


    /**
     * 资讯详情
     */
    public function detail($id = 1)
    {

        // 获取企业信息 根据id
        $where = [
            'deleted' => 0,
            'status' => 0,
            'user_id' => $id
        ];
        $company = SysUser::where($where)->find();
        View::assign('data', $company->toArray());

        // 获取分类信息
        $classify = Classify::where('id', $company['classify_id'])->where('deleted', 0)->find();
        View::assign('classify', $classify);


        // 获取产品列表
        $product_list = Product::where(['user_id' => $company['user_id'], 'deleted' => 0,'status_flag' => 0])
            ->order('create_time desc')->select();
        View::assign('product_list', $product_list->toArray());


        // 获取荣誉资质
        $honor_list = Honor::where(['user_id' => $company['user_id'], 'deleted' => 0,'status_flag' => 0])
            ->order('create_time desc')->select();
        View::assign('honor_list', $honor_list->toArray());


        if ($this->isMobile())
        {
            return View::fetch('wap_detail');
        } else {
            return View::fetch();
        }
    }


}
